﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Product;
using Jzy.Core.Utility;
using Jzy.Core.Common.Web;
using Jzy.Core.Common;
using Jzy.Common;
using Jzy.Core.Common.Basic;
using ECommerce.Model.Product;

namespace ECommerce.Web.ECAdmin.Product
{
    public partial class CommentList : PageList
    {
        private string ProductID
        {
            get
            {
                return Request.QueryString["ProductID"];
            }
        }

        private ECProductCommentBO Comment
        {
            get
            {
                return ECProductCommentBO.Instance<ECProductCommentBO>();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ECProductBO product = new ECProductBO();
                ECProductInfo info = product.GetInfo(ProductID);
                litTitle.Text = "[&nbsp;" + info.Name + "&nbsp;]&nbsp;产品评论";
                BindView();

            }
            base.InitSelectID(hidSelectIDs);
            AddAttr();
        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            PagerSetting setting = new PagerSetting();
            setting.PageIndex = this.PageIndex;
            setting.PageSize = AppConfig.PageSize;
            setting.OrderBy = "InputTime desc";

            string prefix = GlobalVar.WebCurrPath + "CommentList.aspx";
            IEnumerable<ECProductCommentInfo> list = this.Comment.GetList(setting);
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataSource = list;
            lv.DataBind();

            litPager.Text = HtmlPager.Render(setting, prefix, true);
        }

        private void AddAttr()
        {
            JSUtil.ClickBtn(lnkDelete, btnDelete);
            JSUtil.ClickBtn(lnkDisplay, btnDisplay);
            JSUtil.ClickBtn(lnkHide, btnHide);
        }

        protected void btnDisplay_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                Comment.Display(StrUtil.SplitToStr(strSelectIDs));
            }
            BindView();
        }

        protected void btnHide_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                Comment.Hide(StrUtil.SplitToStr(strSelectIDs));
            }
            BindView();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                Comment.Delete(StrUtil.SplitToStr(strSelectIDs));
            }
            BindView();
        }
    }
}